<script type="text/javascript" src="<?=PATH_URL.'static/js/admin/jquery.slugit.js'?>"></script>
<script type="text/javascript">

$(document).ready( function() {
	$("#titleAdmincp").slugIt({
		events: 'keyup blur',
		output: '#slugAdmincp',
		space: '-'
	});
});

function save(){
	var options = {
		success:       showResponse  // post-submit callback 
    };
	$('#contentAdmincp').val(oEdit1.getHTMLBody());
	$('#frmManagement').ajaxSubmit(options);
}

function showResponse(responseText) {
	if(responseText=='success'){
		location.href=root+"admincp/"+module+"/#/save";
	}
	
	if(responseText=='error-title-exists'){
		$('#txt_error').html('Title already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
	
	if(responseText=='error-price-exists'){
		$('#txt_error').html('Price already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
	
	if(responseText=='error-image-exists'){
		$('#txt_error').html('Image already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
	
	if(responseText=='error-content-exists'){
		$('#txt_error').html('Detail already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		return false;
	}
}
</script>
<?php
	function rand_string($length) {
		$chars = "0123456789";
		$size = strlen( $chars );
		$str='';
		for($i=0;$i<$length;$i++ ) {
			$str.= $chars[rand(0,$size-1)];
		}
		return $str;
	}
?>
<div class="gr_perm_error" style="display:none;">
	<p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
	<div class="head_table"><div class="head_title_edit"><?=$this->session->userdata('Name_Module')?></div></div>
	<div class="clearAll"></div>

	<form id="frmManagement" action="<?=PATH_URL.'admincp/'.$module.'/save/'?>" method="post" enctype="multipart/form-data">
	<input type="hidden" value="<?=$id?>" name="hiddenIdAdmincp" />
    <input type="hidden" value="<?=rand_string(4)?>" name="numberAdmincp" />
	<div class="row_text_field_first">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Status:</td>
				<td class="right_text_field"><input <?php if(isset($result->status)){ if($result->status==1){ ?>checked="checked"<?php }}else{ ?>checked="checked"<?php } ?> type="checkbox" class="custom_chk" name="statusAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Tên sản phẩm:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->title)) { print $result->title; }else{ print '';} ?>" type="text" name="titleAdmincp" id="titleAdmincp" /></td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Slug:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->slug)) { print $result->slug; }else{ print '';} ?>" type="text" name="slugAdmincp" id="slugAdmincp" /></td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Category:</td>
				<td class="right_text_field">
                    <select name="categoryAdmincp" id="categoryAdmincp">
                    	<?php 
							if($cate){
								foreach($cate as $row){
						?>
                        <option value="<?=$row->id?>" <?=isset($result->idCategory)&&$result->idCategory==$row->id?"selected='selected'":""?>><?=$row->title?></option>
                        <?php }}?>
                    </select>
                </td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Folder chứa hình:</td>
				<td class="right_text_field">
                	<select name="folderAdmincp" id="folderAdmincp">
                    	<?php 
							if(isset($result->idCategory)){
								foreach($cate as $row){
									if($result->idCategory==$row->id){
						?>
                      	<option value="<?=$row->folder?>"><?=$row->folder?></option>
                        <?php }}}?>
                    </select>
                </td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Sản phẩm mới:</td>
				<td class="right_text_field"><input <?php if(isset($result->news)){ if($result->news==1){ ?>checked="checked"<?php }}else{ ?><?php } ?> type="checkbox" class="custom_chk" name="newAdmincp" /></td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Sản phẩm bán chạy:</td>
				<td class="right_text_field"><input <?php if(isset($result->sellers)){ if($result->sellers==1){ ?>checked="checked"<?php }}else{ ?><?php } ?> type="checkbox" class="custom_chk" name="sellerAdmincp" /></td></td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Sản phẩm khuyến mãi:</td>
				<td class="right_text_field"><input <?php if(isset($result->promotion)){ if($result->promotion==1){ ?>checked="checked"<?php }}else{ ?><?php } ?> type="checkbox" class="custom_chk" name="promotionAdmincp" /></td></td>
			</tr>
		</table>
	</div>
	
	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Giá:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->price_old)) { print $result->price_old; }else{ print '';} ?>" type="text" name="priceOldAdmincp" id="priceOldAdmincp" /></td>
			</tr>
		</table>
	</div>
    
    <div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Giá khuyến mãi:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->price_new)) { print $result->price_new; }else{ print '';} ?>" type="text" name="priceNewAdmincp" id="priceNewAdmincp" /></td>
			</tr>
		</table>
	</div>
	
	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Hình ảnh:</td>
				<td class="right_text_field"><input type="file" name="fileAdmincp[image]" /><?php if(isset($result->image)){ if($result->image!=''){ ?><a class="fancyboxClick" href="<?=PATH_URL.IMAGES_PRODUCTS.$result->image?>" style="margin-left: 20px;color: #3c4049;font-weight: bold">Review</a><?php }} ?></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Chi tiết:</td>
				<td class="right_text_field" style="padding-right: 0px;">
					<textarea name="contentAdmincp" id="contentAdmincp" cols="" rows="8"><?php if(isset($result->detail )) { print $result->detail ; }else{ print '';} ?></textarea>
					<script type="text/javascript">
						var oEdit1 = new InnovaEditor("oEdit1");
						oEdit1.width = "100%";
						oEdit1.cmdAssetManager="modalDialogShow('"+root+"static/editor/assetmanager/assetmanager.php',640,445);";
						oEdit1.REPLACE("contentAdmincp");
					</script>
				</td>
			</tr>
		</table>
	</div>
	</form>
</div>